<template>
  <div class="login">
    <div class="login-div">
      <el-row>
        <el-col :span="8" :offset="8">
          <div class="grid-content bg-purple">
            <el-form
              :model="ruleForm"
              :rules="rules"
              ref="ruleForm"
              label-width="100px"
              class="demo-ruleForm"
            >
              <el-form-item  prop="username" label="用户名">
                <el-input v-model="ruleForm.username">
                  <template slot="prepend"><i class="el-icon-user"></i>
                  </template>
                </el-input>
              </el-form-item>
              <el-form-item label="密码"  prop="password">
                <el-input v-model="ruleForm.password">
                  <template slot="prepend"><i class="el-icon-lock"></i>
                  </template>
                </el-input>
              </el-form-item>
              <el-form-item >
                <el-button type="primary" @click="submitForm('ruleForm')"
                  >立即登录</el-button>
              </el-form-item>
            </el-form>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      ruleForm: {
        username: "",
        password: "",
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名称", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      //this.$refs选择dom节点，方便后续操作
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("填写有误");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>
<style>
.login .login-div {
  width: 100vw;
  height: 100vh;
  background-image: url("../assets/cts-loginbg.jpeg");
}
.login .grid-content {
  padding: 50px;
  background-color: #fff;
  margin-top: 30vh;
}
.el-row {
  margin-bottom: 20px;
}
button.el-button.el-button--primary {
    width: 100%;
}
</style>